'''
1、编写函数实现计算日龄的功能，把列表作为参数。不能用Python内部函数。
2、编写lambda函数实现闰年功能，返回值为【True：闰年，False：非闰年】。可使用条件运算符。

	提示：
		1、当天的日期就是电脑日期。(取日期可用datetime)
'''
import datetime

isLeapYear = lambda x: (x % 4 == 0 and x % 100 != 0) or (x % 400 == 0
                                                         )  # lambda 实现判断闰年


def cntDays(list_):
    cur_day = datetime.date.today()
    month_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]  # 日期表
    days_num = 0
    for i in range(len(list_)):
        birthday = datetime.datetime.strptime(list1[i][3], '%Y%m%d').date()
        for j in range(birthday.year, cur_day.year):
            days_num = days_num + 365 + isLeapYear(i)
        #  减去出生那年未过的天数
        for j in range(1, birthday.month):
            if j == 2:
                days_num -= month_days[j] - isLeapYear(birthday.year)
            else:
                days_num -= month_days[j]
        days_num -= birthday.day  # 减去出生月份一过天数
        # add now year days
        for j in range(1, cur_day.month):
            if j == 2:
                days_num += month_days[j] - isLeapYear(cur_day.year)
            else:
                days_num += month_days[j]
        days_num += cur_day.day
        list_[i][4] = days_num
    return


list1 = [['20021389', '迈子', '男', '20011216', ' '],
         ['20001478', '马大师', '男', '19870624', ' '],
         ['20011267', 'shiina', '女', '20010913', ' ']]

cntDays(list1)
print(list1)